package com.jarvis.du.lifecycle;

import android.arch.lifecycle.Observer;
import android.arch.lifecycle.ViewModelProviders;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.util.Log;
import android.widget.TextView;
import android.widget.Toast;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        getLifecycle().addObserver(new LifeObser());
//        ViewModelProviders.of
//        new ViewModelProvider(this,ViewModelProvider.AndroidViewModelFactory.getInstance(getApplication())).get(MyViewMode.class);
        MyViewMode viewMode = ViewModelProviders.of(this).get(MyViewMode.class);
//        MyViewMode viewMode = ViewModelProvider.AndroidViewModelFactory.getInstance(getApplication()).create(MyViewMode.class);


        viewMode.getInfo().observe(this, new Observer<String>() {
            @Override
            public void onChanged(@Nullable String s) {
                Log.i("TAG", "------S");
                ((TextView)findViewById(R.id.main_tv_normal)).setText(s);
            }

        });


        viewMode.getWifi().observe(this, new Observer<Integer>() {
            @Override
            public void onChanged(@Nullable Integer integer) {
                Toast.makeText(MainActivity.this,"-----Wifi Info"+integer,Toast.LENGTH_SHORT).show();
            }
        });

    }
}
